/* 
 * Copyright (C) 2013, 2014 lex xiang
 *
 * file:	app/boot.c
 * history:	2013 Aug 4 created by lex
 * comment:	
 */

#include "boot.h"
#include "uart.h"

static void boot_image()
{
	printf_d("go! image...\n");

	/* 
	 * in the further, i will move the image from flash to ram, 
	 * and excute it!
	 */

	return;
}

/*	+-------+
 *	|startup|
 *	+-------+
 *	    |
 *          v
 *	+--------------------+
 *	| more devices init  |			<----- s3c2440.S
 *	+--------------------+
 *	    |
 *	    v
 *	+-----------+  'd'
 *	| auto boot |-----+			<----- main.c
 *	+-----------+	  |
 *	'@' |		  |	+-----------------------------------+
 *	    |		  +---->| boot image, startup your systerm  |
 *	    |			+-----------------------------------+
 *	    |
 * +--------+------------------------------------------------------+
 * |	    v							   |
 * |	+-------------------------+				   |
 * |	| tty init and shell init |		<----- main.c	   |
 * |	+-------------------------+				   |
 * |	    |							   |  <-- bootloader
 * |	    v							   |
 * |	+----------------+					   |
 * |	| shell_do_parse |			<----- shell.c	   |
 * |	+----------------+					   |
 * +---------------------------------------------------------------+
 */
void auto_boot()
{
	u32 delay = 3, counter = 0;
	u8  ch;

	printf_d("Please press 'd' to enter  bootloader mode!\n");
	printf_d("Please press '@' to skip   bootloader mode!\n");

	do {
		printf_d("%d\r", delay - counter);

		ch = uart_getc_timeout(0, 1000);
		if (ch == 'd') {
			printf_d("\nEnter bootloader mode!\n");
			return;
		}
		else if (ch == '@') {
			break;
		}
	} while (++counter <= delay);

	boot_image();

	return;
}

